package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sun.org.apache.regexp.internal.RE;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@Api(tags = "后台管理")
@RequestMapping("admin/product")
public class ManageController {

    @Autowired
    ManageService manageService;

    @ApiOperation(value = "查询一级分类")
    @GetMapping("getCategory1")
    public Result getCategory1() {
        List<BaseCategory1> baseCategory1List = manageService.getCategory1();
//        System.out.println("////////////////////////////////");
        System.out.println(baseCategory1List);
        return Result.ok(baseCategory1List);
//        ArrayList<Object> objects = new ArrayList<>();
//        objects.add(1);
//        objects.add(1);
//        objects.add(1);
//        objects.add(1);
//        objects.add(1);
//        return Result.ok(objects);
//        return "啦啦啦";
    }

    @ApiOperation(value = "根据category1Id查询二级分类")
    @GetMapping("getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable("category1Id") Long category1Id) {
        List<BaseCategory2> baseCategory2List = manageService.getCategory2(category1Id);
        return Result.ok(baseCategory2List);
    }

    @ApiOperation("根据category2Id查询三级分类")
    @GetMapping("getCategory3/{category2Id}")

    public Result gery3tCatego(@PathVariable("category2Id") Long category2Id) {
        List<BaseCategory3> baseCategory3List = manageService.getCategory3(category2Id);
        return Result.ok(baseCategory3List);
    }

    //根据一二三级分类的ID 查询平台属性（属性值集合）
    @ApiOperation("根据一二三级分类的ID 查询平台属性（属性值集合） ")
    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result attrInfoList(@PathVariable Long category1Id,
                               @PathVariable Long category2Id,
                               @PathVariable Long category3Id) {
        List<BaseAttrInfo> baseAttrInfoList = manageService.attrInfoList(category1Id, category2Id, category3Id);
        return Result.ok(baseAttrInfoList);
    }

    @ApiOperation(value = "保存平台属性及信息")
    @PostMapping("saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo) {
        manageService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }

    @ApiOperation(value = "数据回显")
    @GetMapping("getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable("attrId") Long attrId) {
        List<BaseAttrValue> AttrValueList = manageService.getAttrValueList(attrId);
        return Result.ok(AttrValueList);
    }

    @ApiOperation(value = "品牌列表分页查询")
    @GetMapping("baseTrademark/{page}/{limit}")
    public Result baseTrademark(@PathVariable("page") Integer page,
                                @PathVariable("limit") Integer limit) {

        IPage iPage = manageService.baseTrademark(page, limit);
        return Result.ok(iPage);
    }

    @ApiOperation("增加品牌列表")
    @PostMapping("baseTrademark/save")
    public Result save(@RequestBody BaseTrademark baseTrademark){
        manageService.save(baseTrademark);
        return Result.ok(baseTrademark);
    }

    @ApiOperation("根据id查询品牌数据")
    @GetMapping("baseTrademark/get/{id}")
    public Result get(@PathVariable("id") Long id){
        BaseTrademark baseTrademark =manageService.get(id);
        return Result.ok(baseTrademark);
    }

    @ApiOperation("修改品牌信息")
    @PutMapping("baseTrademark/update")
    public Result updateById(@RequestBody BaseTrademark baseTrademark){
        manageService.updateById(baseTrademark);
        return Result.ok();
    }

    @ApiOperation("删除品牌列表")
    @DeleteMapping("baseTrademark/remove/{id}")
    public Result removeById (@PathVariable("id") Long id){
        manageService.removeById(id);
        return Result.ok();
    }












    //商品分页查询
    //{page}/{limit}?category3Id=61
    @ApiOperation(value = "商品分页查询")
    @GetMapping("{page}/{limit}")
    public Result productPage(@PathVariable("page") Integer page,
                              @PathVariable("limit") Integer limit,
                              @RequestParam("category3Id") Long category3Id) {

        IPage iPage = manageService.productPage(page, limit, category3Id);
        return Result.ok(iPage);

    }

    @ApiOperation(value = "获取品牌列表")
    @GetMapping("baseTrademark/getTrademarkList")
    public Result getTrademarkList() {
        List<BaseTrademark> getTrademarkList = manageService.getTrademarkList();
        return Result.ok(getTrademarkList);
    }

    @ApiOperation("查询销售属性列表")
    @GetMapping("baseSaleAttrList")
    public Result baseSaleAttrList() {
        List<BaseSaleAttr> baseSaleAttrList = manageService.baseSaleAttrList();
        return Result.ok(baseSaleAttrList);
    }


    //保存spu
    @ApiOperation(value = "保存spu数据")
    @PostMapping("saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfo spuInfo) {
        manageService.saveSpuInfo(spuInfo);
        return Result.ok();
    }

    //回去sku分页列表
    @ApiOperation(value = "获取sku分页列表")
    @GetMapping("list/{page}/{limit}")
    public Result list(@PathVariable("page") Integer page, @PathVariable("limit") Integer limit) {
        IPage iPage = manageService.list(page, limit);
        return Result.ok(iPage);
    }

    //根据supId获取图片列表
    @ApiOperation(value = "根据supId获取图片列表")
    @GetMapping("spuImageList/{spuId}")
    public Result spuImageList(@PathVariable("spuId") Long spuId) {
        List<SpuImage> spuImageList = manageService.spuImageList(spuId);
        return Result.ok(spuImageList);
    }

    //获取spuId获取销售舒心
    @ApiOperation("根据spuId获取销售属性")
    @GetMapping("spuSaleAttrList/{spuId}")
    public Result spuSaleAttrList(@PathVariable("spuId") Long spuId){
        List<SpuSaleAttr> spuSaleAttrList = manageService.spuSaleAttrList(spuId);
        return Result.ok(spuSaleAttrList);
    }

    //添加sku
    @ApiOperation(value = "添加sku")
    @PostMapping("saveSkuInfo")
    public Result saveSkuInfo (@RequestBody SkuInfo skuInfo){
        manageService.saveSkuInfo(skuInfo);
        return Result.ok();
    }


}